{$CLEO .cs}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "Steering wheel"

// By ArtemQa146

if
    0AA2: 31@ = load_dynamic_library "CLEO+.cleo"
then
    if
        0AA4: 30@ = get_dynamic_library_procedure "GetCleoPlusVersion" library 31@
    then
        0AA7: call_function_return 30@ num_params 0 pop 0 29@
        if
            not 29@ >= 0x1020000
        then
            0AD1: show_formatted_text_highpriority "Cleo+ 1.2.0 (or higher) version is required, the DrIVe mod is disabled" time 15000
            0AA3: free_dynamic_library 31@
            0A93: terminate_this_custom_script
        end
        0AA3: free_dynamic_library 31@
    end
else
    0AD1: show_formatted_text_highpriority "Cleo+ 1.2.0 (or higher) version is required, the DrIVe mod is disabled" time 15000
    0AA3: free_dynamic_library 31@
    0A93: terminate_this_custom_script
end

const
    Check = 31@
    Check_Global = 30@
end

while true
wait 0
    if
        player.Defined(0)
    then
    gosub @Check_Global
    if
        Check_Global == true
    then
        repeat
        wait 0
        04ED: load_animation  "DrIVeMod"
        until 04EE:   animation "DrIVeMod" loaded
            
            
while true
wait 0
    gosub @Check_Global
        if
            Check_Global == true
        then
            gosub @Animation
                if
                    check == true
                then
                    046C: 1@ = car 0@ driver
                    if
                        803B:   not 1@ == $PLAYER_ACTOR  // (int)
                    then
                        continue
                    end
                    
                    if or
                        Actor.Animation($PLAYER_ACTOR) == "CAR_Sc1_FL"
                        Actor.Animation($PLAYER_ACTOR) == "CAR_Sc2_FL"
                        Actor.Animation($PLAYER_ACTOR) == "CAR_Sc3_FL"
                        Actor.Animation($PLAYER_ACTOR) == "CAR_Sc4_FL"
                    then
                        continue
                    end
                    
                    if or
                        Actor.Animation($PLAYER_ACTOR) == "DrivebyL_L"
                        Actor.Animation($PLAYER_ACTOR) == "DrivebyL_R"
                        Actor.Animation($PLAYER_ACTOR) == "Driveby_L"
                        Actor.Animation($PLAYER_ACTOR) == "Driveby_R"
                        Actor.Animation($PLAYER_ACTOR) == "CAR_TUNE_RADIO"
                    then
                        continue
                    end

                    if or
                        Actor.Animation($PLAYER_ACTOR) == "gear_ch"
                        Actor.Animation($PLAYER_ACTOR) == "gear_chL"
                        Actor.Animation($PLAYER_ACTOR) == "gear_ch2"
                        Actor.Animation($PLAYER_ACTOR) == "horn"
                        Actor.Animation($PLAYER_ACTOR) == "handbrake"
                        Actor.Animation($PLAYER_ACTOR) == "handbrakeL"
                        0E42: is_char_doing_task_id $PLAYER_ACTOR task_id 1022
                    then
                        continue
                    end
                    if or
                        Actor.Animation($PLAYER_ACTOR) == "drrelaxHL"
                        Actor.Animation($PLAYER_ACTOR) == "drrelaxH"
                        Actor.Animation($PLAYER_ACTOR) == "wopen"
                        Actor.Animation($PLAYER_ACTOR) == "wclose"
                        Actor.Animation($PLAYER_ACTOR) == "startgta4LOWG"
                        Actor.Animation($PLAYER_ACTOR) == "startgta4KartG"
                        Actor.Animation($PLAYER_ACTOR) == "startgta4garage"
                    then
                        continue
                    end
                    if or
                        Actor.Animation($PLAYER_ACTOR) == "startgta41"
                        Actor.Animation($PLAYER_ACTOR) == "startgta4LOW"
                    then
                        continue
                    end
                    0@ = Actor.CurrentCar($PLAYER_ACTOR)
                    0A97: 1@ = vehicle 0@ struct
                    1@ += 0x494 // m_fSteerAngle
                    0A8D: 1@ = read_memory 1@ size 4 virtual_protect 0
                    
                    

                        //   
                        if and
                            not is_char_exiting_any_car $Player_actor
                            80E1:   not player 0 pressed_key 5 //  
                            80E1:   not player 0 pressed_key 7 //  
                            80E1:   not player 0 pressed_key 15 // / Enter/ F
                            1@ > 0.2 //   
                        then
                            1@ *= 1.25
                            if
                                0025:   1@ > 2@  //    ,   ,       
                            then
                                0605: actor $Player_actor perform_animation "DRIVE_L" IFP "DrIVeMod" framedelta 8.0 loop 0 lockX 0 lockY 0 lockF 0 time 1
                                0614: set_actor $Player_actor animation "DRIVE_L" progress_to 1@ // 0.0 to 1.0
                            end
                            0087: 2@ = 1@ // (float)
                            2@ -= 0.05 //      0025:
                        end
                        
                        //   
                        if and
                            not is_char_exiting_any_car $Player_actor
                            80E1:   not player 0 pressed_key 5 //  
                            80E1:   not player 0 pressed_key 7 //  
                            80E1:   not player 0 pressed_key 15 // / Enter/ F
                            1@ < -0.2 //   
                        then
                            1@ *= -1.0 //     
                            1@ *= 1.25
                            if
                                0025:   1@ > 2@  // //    ,   ,       
                            then
                                0605: actor $Player_actor perform_animation "DRIVE_R" IFP "DrIVeMod" framedelta 8.0 loop 0 lockX 0 lockY 0 lockF 0 time 1
                                0614: set_actor $Player_actor animation "DRIVE_R" progress_to 1@ // 0.0 to 1.0
                            end
                            0087: 2@ = 1@ // (float)
                            2@ -= 0.05 //      0025:
                        end
                    end
                else
                    04EF: release_animation "DrIVeMod"
                    break
                end
            end
        end
    end
end
    

:Animation
check = true
    //    
    if or
        Actor.Animation($PLAYER_ACTOR) == "CAR_Lsit"
        Actor.Animation($PLAYER_ACTOR) == "Drive_LO_L"
        Actor.Animation($PLAYER_ACTOR) == "Drive_LO_R"
    then
        check = false
    end
    // 
    if or
        Actor.Animation($PLAYER_ACTOR) == "KART_drive"
        Actor.Animation($PLAYER_ACTOR) == "KART_L"
        Actor.Animation($PLAYER_ACTOR) == "KART_R"
    then
        check = false
    end
return

:Check_Global
Check_Global = false
    if and
        Actor.Driving($PLAYER_ACTOR)
        8741:   not actor $PLAYER_ACTOR busted
        not actor.Dead($PLAYER_ACTOR)
        not is_on_cutscene
        not is_on_scripted_cutscene
    then
        if and
            84C8:   not actor $PLAYER_ACTOR driving_flying_vehicle
            847A:   not actor $PLAYER_ACTOR driving_bike
            84A7:   not actor $PLAYER_ACTOR driving_boat
            84A9:   not actor $PLAYER_ACTOR driving_heli
            89AE:   not actor $PLAYER_ACTOR driving_train
        then
            0@ = Actor.CurrentCar($PLAYER_ACTOR)
            0E12: get_vehicle 0@ subclass_to 1@
            if
                1@ == 0
            then
                Check_Global = true
            end
        end
    end
return

